package leetcode_401_500;

import java.util.Arrays;
import java.util.Comparator;

public class LeeCode_452 {
    public static void main(String[] args) {
        System.out.println(findMinArrowShots(new int[][]{{3, 9}, {7, 12}, {3, 8}, {6, 8}, {9, 10}, {2, 9}, {0, 9}, {3, 9}, {0, 6}, {2, 8}}));
    }
    private static int findMinArrowShots(int[][] points) {
        Arrays.sort(points, Comparator.comparingInt(o -> o[1]));
        int ans = 1, min = points[0][0], max = points[0][1];
        for (int i = 1; i < points.length; i++) {
            min = Math.max(min, points[i][0]);
            max = Math.min(max, points[i][1]);
            if (min > max){
                ans++;
                min = points[i][0];
                max = points[i][1];
            }
        }
        return ans;
    }
}
